﻿@model ForumPageModel
@using Nop.Core.Domain.Forums;
@using Nop.Web.Extensions;
@using Nop.Web.Models.Boards;
@using Nop.Web.Models.Common;
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    Html.AddTitleParts(Model.Name);
}
@Html.Action("ForumBreadcrumb", new { forumId = Model.Id })
@Html.Partial("_SearchBox")
<div class="page forum-page">
    <div class="forum-top">
        <div class="forum-info">
            <div class="forum-name">
                @Model.Name
            </div>
            <div class="forum-description">
                @Model.Description
            </div>
            @if (Model.ForumFeedsEnabled)
            {
                <a href="@Url.RouteUrl("ForumRSS", new { id = Model.Id })" class="link-rss" title="@T("Forum.ForumRSSLinkTitle")">@T("Forum.RSS")</a>
            }
        </div>
        <div class="actions">
            <div>
                @Html.RouteLink(T("Forum.NewTopic").ToString(), "TopicCreate", new { id = Model.Id }, new { @class = "newtopic" })
                @if (Model.IsCustomerAllowedToSubscribe)
                {
                    <a class="watch-forum" href="#" id="watch-forum">@Model.WatchForumText</a>
                    <script type="text/javascript">
                        $(function () {
                            $('#watch-forum').click(function () {
                                $.ajax({
                                    cache: false,
                                    type: 'POST',
                                    url: '@Url.RouteUrl("ForumWatch", new { id = Model.Id })',
                                    dataType: 'json',
                                    success: function (data) {
                                        $('#watch-forum').text(data.Text);
                                    },
                                    error: function (xhr, ajaxOptions, thrownError) {
                                        alert('Failed to watch');
                                    }
                                });
                            });
                        });
                    </script>
                }
            </div>
        </div>
    </div>
    <div class="pager upper">
        @{
            var pager = Html.Pager(new PagerModel()
            {
                PageSize = Model.TopicPageSize,
                TotalRecords = Model.TopicTotalRecords,
                PageIndex = Model.TopicPageIndex,
                ShowTotalSummary = false,
                RouteActionName = "ForumSlugPaged",
                UseRouteLinks = true,
                RouteValues = new RouteValues { id = Model.Id, slug = Model.SeName }
            });
        }
        @pager
    </div>
    <div class="forums-table-section topics-group">
        @if (Model.ForumTopics.Count > 0)
        {
            <table>
                <thead>
                    <tr>
                        <th class="topic-name" colspan="2">
                            @T("Forum.TopicTitle")
                        </th>
                        <th class="replies">
                            @T("Forum.Replies")
                        </th>
                        <th class="views">
                            @T("Forum.Views")
                        </th>
                        <th class="last-post">
                            @T("Forum.LatestPost")
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var topic in @Model.ForumTopics)
                    {
                        <tr>
                            <td class="image">
                                @{
                        var topicType = "post";
                        var topicText = String.Empty;
                        switch (topic.ForumTopicType)
                        {
                            case ForumTopicType.Normal:
                                topicType = "post";
                                break;
                            case ForumTopicType.Sticky:
                                topicType = "poststicky";
                                topicText = string.Format("[{0}]", T("Forum.Sticky").ToString());
                                break;
                            case ForumTopicType.Announcement:
                                topicType = "post-annoucement";
                                topicText = string.Format("[{0}]", T("Forum.Announcement").ToString());
                                break;
                            default:
                                topicType = "post";
                                break;
                        }
                                    <div class="@topicType">
                                    </div>
                                }
                            </td>
                            <td class="topic-name">
                                @if (!String.IsNullOrEmpty(topicText))
                                {
                                    <span class="topic-type">@topicText</span>
                                }
                                @Html.RouteLink(topic.Subject, "TopicSlug", new { id = topic.Id, slug = topic.SeName }, new { @class = "topic-title" })
                                @if (topic.NumPosts > Model.PostsPageSize)
                                {
                                    <div class="topicspager">
                                        @Html.ForumTopicSmallPager(topic)
                                    </div>
                                }
                                <div class="topic-starter">
                                    @if (topic.CustomerId > 0)
                                    {
                                        <label>@T("Forum.Author"):</label>
                                        if (topic.AllowViewingProfiles && !topic.IsCustomerGuest)
                                        {
                                        @Html.RouteLink(topic.CustomerName, "CustomerProfile", new { Id = topic.CustomerId })
                                        }
                                        else
                                        {
                                        @topic.CustomerName
                                        }
                                    }
                                </div>
                            </td>
                            <td class="replies">
                                @topic.NumReplies
                            </td>
                            <td class="views">
                                @topic.Views
                            </td>
                            <td class="last-post">
                                @Html.Action("LastPost", new { forumPostId = topic.LastPostId, showTopic = false })
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        }
    </div>
    <div class="pager lower">
        @pager
    </div>
</div>
